<?php

/*
 * Action - Reaction 3$
 *
 * +1 Card
 * +1 Action
 * +1 Buy
 * When one of your cards is trashed, you may discard this from your hand. If you do, gain a Gold.
 */

class MarketSquare extends Card implements iAction, iKingdom, iDarkAges, iReactingCard {

    public function __construct() {
        parent::__construct("Market Square", 3);
        $this->undoPlay = false;
        $this->undoBuy = true;
        
        $this->reactConditions = new ReactionConditions();
        $this->reactConditions->action = array(Trashed);
        $this->reactConditions->actor = array(Yourself);
        $this->reactConditions->cardLocation = array(PlayHand);
        $this->reactConditions->limit = ForEachCard;
        $this->reactConditions->isMandatory = false;
    }

    public function getDescription() {
        return array(
            "+1 Card",
            "+1 Action",
            "+1 Buy",
            "When one of your cards is trashed, you may discard this from your hand. If you do, gain a Gold.");
    }

    public function getConditions() {
        return $this->reactConditions;
    }

    public function isReactRelevant(Game $game, $card, $name) {
        if ($card) {
            return true;
        }
        return false;
    }

    public function react(Game $game, $card, $name) {
        if ($card) {
            $options = array(new Option(1, "Yes"), new Option(2, "No"));
            $output = MySocket::GetUserReply($game, Input_ChooseOne, $options, 1, 1, null, "Discard Market Square from your hand", $name);
            $answer = $output[0];
            if ($answer == "Yes") {
                $game->moveCardFromPileToPile($this, PlayHand, DiscardPile, $name);
                $gold = $game->moveCardFromPileToPile("Gold", BoardCards, DiscardPile, $name);
                ScreenDisplay::addScreenMessage($game, true, "discard " . nicePrint($this) . " and gain " . nicePrint($gold), "discards " . nicePrint($this) . " and gains " . nicePrint($gold), $name);
                $game->setTempCard($card);
            } 
        }
        return true;
    }

    public function play(Game $game, $isRealCard) {
        $game->addActions(1);
        $game->addBuys(1);
        $drawedCards = $game->drawCards(1);

        ScreenDisplay::addScreenMessage($game, true, "get +1 action, +1 buy and draw ".nicePrint($drawedCards), "get +1 action, +1 buy and draws ".sizeof($drawedCards)." cards");
        $game->cardActionFinished();
        return true;
    }

}

?>